package com.shj.web.controller;

import com.shj.model.PageRequest;
import com.shj.model.PageResult;
import com.shj.model.SysRole;
import com.shj.service.SysRoleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;

/**
 * (SysRole)表控制层
 *
 * @author makejava
 * @since 2020-03-12 13:00:29
 */
@Controller
@RequestMapping("/system/role")
public class SysRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;

    /**
     * @description 获取数据并分页
     * @author songhuajian
     * @date 2020/3/24 14:03
     */
    @GetMapping("/list")
    @ResponseBody
    public PageResult selectPage(PageRequest pageRequest){
        return sysRoleService.findPage(pageRequest);
    }

    /**
     * @description 根据roleId获取数据
     * @author songhuajian
     * @date 2020/3/24 14:04
     */
    @PostMapping("/one")
    @ResponseBody
    public SysRole findOne(@RequestBody HashMap<String, String> map){
        String roleId = map.get("roleId");
        return sysRoleService.queryByRoleId(roleId);
    }

    /**
     * @description 添加角色
     * @author songhuajian
     * @date 2020/3/24 14:06
     */
    @PostMapping("/add")
    @ResponseBody
    public void add(@RequestBody @Valid SysRole sysRole){
        sysRoleService.insert(sysRole);
    }

    /**
     * @description 修改角色
     * @author songhuajian
     * @date 2020/3/24 14:06
     */
    @PostMapping("/edit")
    @ResponseBody
    public void update(@RequestBody @Valid SysRole sysRole){
        sysRoleService.update(sysRole);
    }

    /**
     * @description 删除角色
     * @author songhuajian
     * @date 2020/3/24 14:06
     */
    @PostMapping("/delete")
    @ResponseBody
    public void delete(@RequestBody HashMap<String, String> map){
        String roleId = map.get("roleId");
        sysRoleService.delete(roleId);
    }
}